/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package games;

/**
 *
 * @author Mikael
 */
public class MikaelHeuristic extends KamisadoState {

    @Override
    protected int heuristic(boolean player) {
        

        int score = 0;
        for (Tower tower : this.towerPositions.keySet()) {
            score += getPositionScore(tower, player);
            score += getBlockedScore(tower, player);
        }

        return score;

    }

    private int getPositionScore(Tower tower, boolean player) {
        Coordinate coord = this.towerPositions.get(tower);
        int yModifier = player ? 1 : -1;
        
        if(yModifier < 0){
                return (7 - coord.Y) * 10;
        }else{
            return coord.Y * 10;
        }
        
    }
    
    private int getBlockedScore(Tower tower, boolean player) {
        Coordinate coord = this.towerPositions.get(tower);
        int yModifier = player ? 1 : -1;
        
        if (tower.getPlayer() == player) {
            int y = coord.Y + yModifier;
            if(y > 7 || y < 0){
                return 0;
            }

            for (int x = Math.max(0, coord.X - 1); x < Math.min(7, coord.X); x++) {
                if(this.getTower(x, y) == null){
                    return 0;
                }
            }
            return -2000;
        }else{
            int y = coord.Y - yModifier;
            if(y > 7 || y < 0){
                return 0;
            }

            for (int x = Math.max(0, coord.X - 1); x < Math.min(7, coord.X); x++) {
                if(this.getTower(x, y) == null){
                    return 0;
                }
            }
            return 2000;
        }
    }
}
